library(dplyr)
library(readstata13)

## set working directory to replication 
## folder

survey <- read.dta13("Harris_Data/Harris 1972 Public Opinion Survey, study no. 2221/harris_s2221_spss.dta")

# pid
survey$pid <- c(1:nrow(survey))

# study 
survey$study <- as.character(2221)

# study year (year)
survey$year <- 1972

# geographic data (urban)
survey$urban <- as.character(survey$S13)

# geographic data (region)
survey$region <- as.character(survey$S11)
class(survey$region)

# respondent head of household (hh)
survey$hh <- NA

# increasing inequality (inequality)
survey$inequality <- as.character(survey$Q10_A) # already harmonized

# inequality variable (inequality.variable)
survey$inequality.variable <- 1

# union (union.self)
survey$union.self <- NA

# union (union.other) 
survey$union.other <- NA

# employment (employed)
survey$employed <- NA

## employed self
survey$employed.self <- NA

# occupation
survey$occupation <- NA

## occupation self
survey$occupation.self <- NA

# household size (hhsize)
survey$hhsize <- NA

# education (educ)
survey$educ <- NA                         

# household income (income)
survey$income <- NA

# age
survey$age <- NA

# race
survey$race <- NA

# politics (party)
survey$party <- NA

# politics (ideology)
survey$ideology <- as.character(survey$Q19)

# gender
survey$gender <- NA

# religion
survey$religion <- NA

## factuals
survey$factual1 <- NA
survey$factual2 <- NA
survey$factual3 <- NA

## alienation index
survey$dontcare <- as.character(survey$Q10_B)
survey$dontcount <- as.character(survey$Q10_C)
survey$leftout <- as.character(survey$Q10_D)

## question placement
survey$question_place <- "after party"

# subset
survey_2221 <- survey[,c("pid", "study", "year", "urban", "region", "hh",
                         "inequality", "inequality.variable", "union.self", "union.other",
                         "employed", "employed.self", "occupation", "occupation.self", "hhsize", "educ", "income", 
                         "age", "race", "party", "ideology", "gender", "religion",
                         "factual1", "factual2", "factual3", "dontcare", "dontcount", "leftout",
                         "question_place")]

# save file
#saveRDS(survey_2221, file = "Harris_Data/survey_2221.rds")
